/******************************************************************************
*	cm.h	Header file of CM Library
*
*	coypright (C) 2009 Ding Lixing
*
******************************************************************************/
#ifndef __CM_INC__
#define __CM_INC__

#ifdef __cplusplus
extern "C" {
#endif

#include "vm.h"
#include "cmList.h"

/* CM CONFIG */
#ifndef CM_CFG_TICKS_PER_SECOND
#define CM_CFG_TICKS_PER_SECOND (100)
#endif

#ifndef CM_CFG_TASK_PRIO_LEVEL
#define CM_CFG_TASK_PRIO_LEVEL  (32)
#endif

#ifndef CM_CFG_TASK_SLEEP_LEVEL
#define CM_CFG_TASK_SLEEP_LEVEL (32)
#endif

/* CM SW IRQ CALL */
#define CM_SW_SWITCHCTX         (0)

/* CM options */
#define CM_OP_PRIO              (0x1)
#define CM_OP_FIFO              (0x0)
#define CM_OP_CEIL              (0x2)
#define CM_OP_MASK              (0x3)

/* CM sleep time */
#define CM_SLEEP_NEVER          (0)
#define CM_SLEEP_FOREVER        ((unsigned int)-1)

/* CM task flags */
#define CM_TFG_ACTIVE           (0x80)
#define CM_TFG_SLEEP            (0x40)
#define CM_TFG_SUSPEND          (0x20)
#define CM_TFG_ALL              (0xFF)

#define CM_OBJ_MASK             (0x07)
#define CM_OBJ_NULL             (0x00)
#define CM_OBJ_SEM              (0x01)
#define CM_OBJ_MUTEX            (0x02)
#define CM_OBJ_QUEUE_RECV       (0x03)
#define CM_OBJ_QUEUE_SEND       (0x04)
#define CM_OBJ_COND             (0x05)
#define CM_OBJ_USR1             (0x06)
#define CM_OBJ_USR2             (0x07)

/* CM condition wait type */
#define CM_COND_WAIT_ALL        (0x00)
#define CM_COND_WAIT_ANY        (0x01)
#define CM_COND_WAIT_CLR        (0x02)

/* CM error code define */
#define CM_ERR_InvalidArgument      (-1001)
#define CM_ERR_StartingActiveTask   (-1002)
#define CM_ERR_WakeNosleepingTask   (-1003)
#define CM_ERR_SemOverflow          (-1004)
#define CM_ERR_SemExhausted         (-1005)
#define CM_ERR_MutexNotOwner        (-1006)
#define CM_ERR_MutexNotFree         (-1007)
#define CM_ERR_QueueSendToFull      (-1008)
#define CM_ERR_QueueRecvFromEmpty   (-1009)
#define CM_ERR_CondNotMatch         (-1010)
#define CM_ERR_CoreFail             (-1011)

#include "cmTask.h"
#include "cmSem.h"
#include "cmMutex.h"
#include "cmQueue.h"
#include "cmCond.h"

#ifdef __cplusplus
}
#endif

#endif /* __CM_INC__ */

